#ifndef VDataView_H
#define VDataView_H

#include "VCfg.h"
#include "VDataModel.h"
#include "VItemDelegate.h"

///////////////////////////////////////////////////////////////////////////////
class VDataView;
///////////////////////////////////////////////////////////////////////////////

class VDataViewActions : public QObject
{
	Q_OBJECT

public:
	VDataViewActions(VDataView *view);
	~VDataViewActions();

	QToolBar *toolBar() const { return m_toolbar;}

	void update();

private:
	VDataView *m_view;
	QToolBar *m_toolbar;
	QAction* m_appendRecord;
	QAction* m_deleteRecord;
	QAction* m_editRecord;
};

///////////////////////////////////////////////////////////////////////////////

class VDataViewTV : public QTableView
{
public:
	explicit VDataViewTV(QWidget *parent = 0) :QTableView(parent) {}

protected:
	void resizeEvent(QResizeEvent *event);
};

///////////////////////////////////////////////////////////////////////////////

class VDataView : public QObject
{
	Q_OBJECT
	
public:
	VDataView(QObject *parent = 0);
	~VDataView();
	
	QTableView *view() const { return m_view;}
	VDataViewActions &actions() { return m_actions;}

	void setDataModel(VDataModel *dataModel);
	
public slots:	
	void rowChanged(const QModelIndex &index);
	void edit();
	void appendRecord();
	void deleteRecord();
	void modelReset();

private:
	VDataViewTV *m_view;
	VDataModel *m_dataModel;
	VDataViewActions m_actions;
	friend VDataViewActions;
};

///////////////////////////////////////////////////////////////////////////////

#endif
